<template>
    <div class="white-search-bar"></div>
</template>

<script>

export default {
  data () {
    return {
    }
  },
  created() {
    this.init()
  },
  methods: {
    getType (value) {
      var str = Object.prototype.toString.call(value);
      str = str.split(' ')[1].replace(/\]/, '').toLowerCase()
      console.log(str)
      return str
    },
    init () {
      this.getType({}); // "object"
      this.getType([]); // "array"
      this.getType(5); // "number"
      this.getType(null); // "null"
      this.getType(undefined); // "undefined"
      this.getType(/abcd/); // "regex"
      this.getType(new Date()); // "date"
      var oldInfo = {
        name: 'sw',
        old: '22',
        tel: '13263505780',
        home: {
          city: 'shenzhen'
        }
      }
      var newInfo = this.deepCopy(oldInfo)
      newInfo.old = '23'
      console.log(oldInfo);
      console.log(newInfo);
    },
    // 深拷贝函数
    deepCopy(originObj) {
      var newObj = Array.isArray(originObj) ? [] : {};
      if (originObj && typeof originObj === "object") {
        for (var i in originObj) {
          if (originObj.hasOwnProperty(i)) {
            // 如果子属性为引用数据类型，递归复制
            if (originObj[i] && typeof originObj[i] === "object") {
              newObj[i] = this.deepCopy(originObj[i]);
            } else {
              // 如果是基本数据类型，简单复制
              newObj[i] = originObj[i];
            }
          }
        }
      }
      return newObj;
    }
  }, 
}
</script>

<style scoped>
</style>
